home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / LIB / SAFEOUT.C < prev    next >
C/C++ Source or Header  |  1993-10-02  |  5KB  |  141 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    s a f e o u t . c                                               */
  3. /*                                                                    */
  4. /*    Console I/O functions for use during interrupt processing       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: safeout.c 1.5 1993/10/03 00:05:32 ahd Exp $
  21.  *
  22.  *    Revision history:
  23.  *    $Log: safeout.c $
  24.  *     Revision 1.5  1993/10/03  00:05:32  ahd
  25.  *     Only define currentfile() under Windows NT
  26.  *
  27.  *     Revision 1.4  1993/09/20  04:39:51  ahd
  28.  *     OS/2 2.x support
  29.  *
  30.  *     Revision 1.3  1993/07/20  21:42:43  dmwatt
  31.  *     Don't rely on standard I/O under Windows/NT
  32.  *
  33.  */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*    Since C I/O functions are not safe inside signal routines,      */
  37. /*    the code uses conditionals to use system-level DOS and OS/2     */
  38. /*    services.  Another option is to set global flags and do any     */
  39. /*    I/O operations outside the signal handler.                      */
  40. /*--------------------------------------------------------------------*/
  41.  
  42. #define __MSC                 /* Make Borland C++ 2.0 act like MS C  */
  43.  
  44. #include <stdio.h>
  45.  
  46. #ifdef WIN32
  47.     #include <windows.h>
  48.     #include <string.h>
  49.  
  50. #elif defined( FAMILYAPI ) || defined(__OS2__)
  51.  
  52.     #define INCL_NOCOMMON
  53.     #define INCL_NOPM
  54.     #define INCL_VIO
  55.     #define INCL_KBD
  56.     #include <os2.h>
  57.     #include <string.h>
  58.  
  59. #else
  60.  
  61.     #include <dos.h>
  62.     #include <bios.h>
  63.     #include <conio.h>
  64.  
  65. #endif /* FAMILYAPI */
  66.  
  67. /*--------------------------------------------------------------------*/
  68. /*                    UUPC/extended include files                     */
  69. /*--------------------------------------------------------------------*/
  70.  
  71. #include "lib.h"
  72. #include "safeio.h"
  73.  
  74. /*--------------------------------------------------------------------*/
  75. /*                          Global variables                          */
  76. /*--------------------------------------------------------------------*/
  77.  
  78. #if defined(WIN32)
  79. currentfile();
  80. #endif
  81.  
  82. #if defined(WIN32)
  83. static HANDLE hConsoleOut = INVALID_HANDLE_VALUE;
  84.  
  85. void InitConsoleOutputHandle(void)
  86. {
  87.    hConsoleOut = CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE,
  88.       FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
  89.       FILE_ATTRIBUTE_NORMAL, 0);
  90.  
  91.    if (hConsoleOut == INVALID_HANDLE_VALUE) {
  92.       printmsg(0, "InitConsoleHandles:  could not open console handles!");
  93.       panic();
  94.    }
  95. }
  96. #endif
  97.  
  98. /*--------------------------------------------------------------------*/
  99. /*    s a f e o u t                                                   */
  100. /*                                                                    */
  101. /*    Outputs a string using system level calls. from MicroSoft       */
  102. /*    Programmer's Workbench QuickHelp samples                        */
  103. /*--------------------------------------------------------------------*/
  104.  
  105. void safeout( char *str )
  106. {
  107.  
  108. #ifdef _Windows
  109.  
  110.    fputs( str , stdout );
  111.    return;
  112.  
  113. #elif defined( WIN32 )
  114.  
  115.    DWORD dwBytesWritten;
  116.  
  117.    if (hConsoleOut == INVALID_HANDLE_VALUE)
  118.       InitConsoleOutputHandle();
  119.  
  120.    WriteFile(hConsoleOut, str, (DWORD)strlen(str), &dwBytesWritten, NULL);
  121.    return;
  122.  
  123. #elif defined( FAMILYAPI ) || defined(__OS2__)
  124.  
  125.    VioWrtTTY( str, strlen( str ), 0 );
  126.  
  127. #else
  128.     union REGS inregs, outregs;
  129.  
  130.     inregs.h.ah = 0x0e;
  131.     while( *str )
  132.     {
  133.         inregs.h.al = *str++;
  134.         int86( 0x10, &inregs, &outregs );
  135.     }
  136.  
  137.     safeflush();              /* Flush keyboard                      */
  138.  
  139. #endif /* _Windows */
  140. } /* safeout */
  141.